#coding:utf-8

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from model.order import Order
import time
import datetime

engine = create_engine('mysql+pymysql://root:root@192.168.1.8:3306/ucenter?charset=utf8', echo=True, encoding="utf-8")
Session = sessionmaker(bind=engine)

class DBHelper(object):

	def __init__(self):
		self.session = Session()

	def set_model(self, model):
		self.model = model

	def get_all(self):
		list = self.session.query(self.model).all()
		self.session.close()
		return list

	def get_by_id(self, id):
		res = self.session.query(self.model).filter(self.model.id == id).first()
		self.session.close()
		return res

	def get_by_param(self, **kws):
		first = self.session.query(self.model)
		for key in kws.iterkeys():
			first = first.filter(getattr(self.model, key) == kws[key])
		list = first.all()
		self.session.close()
		return list

	
